<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semanticui/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <title>候选人简历</title>  
</head>
<body>
<div class="ui segment" id="n-page">
                                    
<%--<c:choose> --%>
<%--    <c:when test="${null!= employee}">   --%>
<%--        <input type="hidden" name="empId" id="empId" value="${employee.id}" />--%>
<%--    </c:when> --%>
<%--    <c:otherwise>   --%>
<%--        <input type="hidden" name="empId" id="empId" value="0" />--%>
<%--    </c:otherwise> --%>
<%--</c:choose>     --%>
        <div class="ui segment" id="n-content">
            <form class="ui form">
                <div class="field">
                    <label><span style="color: red">*</span>>候选人姓名</label>
                    <div class="ui input">
                   		<input type="hidden" name="jobId" id="jobId" value="${jobId}" />
                        <input type="text" id="name" name="name"  placeholder="请输入候选人的姓名">
                    </div>
                </div>
                <div class="field">
                    <label><span style="color: red">*</span>>联系电话</label>
                    <div class="ui input">
                        <input type="text" id="mobile" name="mobile" placeholder="请输入候选人的手机号码">
                    </div>
                </div>
                <div class="field">
                    <label><span style="color: red">*</span>>年龄</label>
                    <div class="ui input">
                        <input type="text" id="age" name="age" placeholder="请输入候选人的年龄">
                    </div>
                </div>
                <div class="field">
                    <label><span style="color: red">*</span>>所在城市</label>
                    <select name="cityId" id="cityId"  class="ui search dropdown">
                    <option value="">请输入所在城市名称</option>
                    <c:forEach items="${cities}" var="city">
                        <option value="${city.id}">${city.name}</option>

                    </c:forEach>
                    </select>
                </div>
                <div class="field">
                    <label><span style="color: red">*</span>>现任公司</label>
                    <div class="ui search" id="companyname" name="companyname">
                        <div class="ui input">
                            <input class="prompt" type="text" placeholder="请输入公司名称" value="${employee.companyName}">
                        </div>
                        <div class="results"></div>
                    </div>
                </div>
                <div class="field">
                    <label><span style="color: red">*</span>>现任职位</label>
                    <select id="roleId" class="ui search dropdown">
                    <option value="">请输入现任职位名称</option>
                    <c:forEach items="${roles}" var="role">
                            <option value="${role.id}">${role.name}</option>
                    </c:forEach>
                   
                    </select>
                </div>
                <div class="field">
                    <label><span style="color: red">*</span>>现任工作年限</label>
                    <div  class="ui input">
                        <input id="workAge" type="text" name="duration"  placeholder="请输入现任工作年限">
                    </div>
                </div>
                <div class="field">
                    <label><span style="color: red">*</span>>工作状态</label>
                    <select id="inService" class="ui selection dropdown">
	                    <option value="0">在职</option>
	                    <option value="1">离职</option>
                    </select>
                </div>
                <div class="field">
                    <label><span style="color: red">*</span>>推荐理由</label>
                    <div class="ui input" >
                        <input id ="reason" style="border: 1px solid #1fbad6;"  type="text" name="reason" placeholder="请输入您的推荐理由">
                    </div>
                </div>


            </form>        
        </div>

        <div class="ui segment" id="cont-next">
            <div class="fluid ui button" id="next">推荐</div>
        </div>

</div>

<script src="${ctx}/resources/jweixin-1.0.0.js"></script>

<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semanticui/semantic.js" type="text/javascript"></script>
<script type="text/javascript">

/* wx.config({
    debug: false, 
    appId: "${config.appid}",  
    timestamp: ${config.currenttimestamp},  
    nonceStr: "${config.nonceStr}", 
    signature: "${config.signatureStr}", 
    jsApiList: ['checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'hideOptionMenu']  
}); */


    var handler = { 
        activate: function() { 
            $(this).addClass('active').siblings().removeClass('active'); 

            if($(this).attr('id') == 'next') {
            	var jobId=$("#jobId").val();
                var companyname = $("#companyname").search('get value');
                var roleId = $("#roleId").val();
                var name = $("#name").val();
                var age = $("#age").val();
                var workAge = $("#workAge").val();
                var inService = $("#inService").val();
                var reason = $("#reason").val();
                var phone = $("#mobile").val();
                var empId = $("#empId").val();
                var cityid    = $("#cityId").val();
           		

                if(!roleId) {
                    alert("您必须选择一个职位名称");
                    return false;
                }
                if(!name || name =="" || name.length>40)
                {
                    alert("您必须输入合格的姓名");
                    return false;
                }
                if(!cityid) {
                    alert("您必须选择一个城市");
                    return false;
                }
                if(!companyname || companyname =="" || companyname.length>40)
                {
                    alert("您必须输入合格的公司名称");
                    return false;
                }
                if(!phone || phone == "")
                {
                    alert("您必须输入电话号码");
                     //focus
                    return false;
                }
                if(phone.length <5 || phone.length>18) {
                    alert("您必须输入合格的电话");
                    return false;
                }
                var regEx1 = /^([0-9]|[\-])+$/g;
                if (!phone.match(regEx1)) {
                    alert("您必须输入合格的电话");
                    return false;
                }
                if(!reason || reason == "")
                {
                    alert("您必须输入推荐理由");
                    //focus
                    $("#reason").focus();
                    return false;
                }
                if(reason.length>40) {
                    alert("您必须输入合格的推荐理由");
                    return false;
                }
                if(!/^[0-9]+$/.test(age) || age < 10 || age > 80) {
                    alert("您必须输入年龄"); 
                    return false;
                }
                if(!/^[0-9]+$/.test(workAge) || workAge <= 0 || workAge > 60) {
                    alert("您必须输入工作年限"); 
                    return false;
                }

                var postUrl = '${ctx}/wechat/headhunter/recommend/recommend.do';
                
                var param = {};
                param['jobId']  = jobId;
                param['reason'] = reason;
                param['roleId'] = roleId;
                param['name']   = name;        
                param['phone']  = phone;
                param['age']    = age;
                param['workage'] = workAge;
                param['inservice']   = inService;
                param['companyName'] = companyname;
                param['cityId'] = cityid;

                $.ajax({ 
                    url: postUrl, 
                    type: "POST", 
                    data: param,
                    success: function(data) { 
                        if(data.errorcode == 0)
                        {
                            <%--var id = data.recommendId--%>
                            <%--var redirectUrl =  '${ctx}/wechat/headhunter/toConfirm.page?recommendId='+id;--%>
                            <%--location.href = redirectUrl;--%>
                            alert("恭喜你推荐完成");
                            wx.closeWindow();
                        } else if(data.errorcode == -2) {
                            //var errorUrl = '${ctx}/wechat/headhunter/jobdetail.page?id=' + data.jobid;
                            //alert(data.msg);
                            var errorUrl = '${ctx}/wechat/hunter/main.page';
                            location.href = errorUrl;
                        } else {
                            var errorUrl = '${ctx}/wechat/headhunter/error.page';
                            alert(data.msg);
                            //location.href = errorUrl;
                        }
                    }, 
                    error: function() { 
                        alert("服务出错，请稍后尝试"); 
                    } 
                });
            }
        } 
    };

    var companydata = [];
    
    <c:forEach items="${companies}" var="company">
        var tmp${company.id} = {};
        tmp${company.id}.title = "${company.name}";
        companydata.push(tmp${company.id});
    </c:forEach>

    $(document).ready(function() { 
        
            $('.button').on('click', handler.activate);
            $('.dropdown').dropdown({
                fullTextSearch:true,
            });
            $('.ui.search').search({
                source: companydata,
                searchFullText: true
            });
            wx.ready(function() { 
            wx.hideOptionMenu();
        });
    });

</script>
</body>
</html>